package com.example.InetAddressDemos;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author Jason
 * @PACKAGE_NAME com.example.InetAddressDemos
 * @Description InetAddressDemo网络类
 * @date 2023-12-14 21:57
 */
public class InetAddressDemo {
    public static void main(String[] args) throws UnknownHostException {
        //获取InetAddress对象
//        InetAddress byName = InetAddress.getByName("127.0.0.1");
        InetAddress byName = InetAddress.getByName("DESKTOP-TRDCC51");
        System.out.println(byName);

        //获取设备名 / IP的对象
        InetAddress address = InetAddress.getLocalHost();
        System.out.println(address);

        String name = address.getHostName();
        System.out.println(name);

        String ip = address.getHostAddress();
        System.out.println(ip);

    }
}
